package com.uenpay.oem.ui.main.my;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.socks.library.KLog;
import com.uenpay.im.utilities.ToastUtil;
import com.uenpay.oem.R;
import com.uenpay.oem.data.bean.UserAuthInfo;
import com.uenpay.oem.ui.reserver.RechargeActivity;
import com.uenpay.oem.ui.withdraw.WithdrawActivity;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.service.bean.TransBankCardList;
import com.uenpay.util.app.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by PS on 2017/6/29.
 */

public class MyBalanceActivity extends BaseActivity implements MyBalanceContract.View {
    @BindView(R.id.tv_maney)
    TextView tvmaney;
    private UserAuthInfo mUserAuthInfo = null;
    private String mBalance;
    private MyBalanceContract.Presenter mmybalancepresenter;
    private TransBankCardList<BankCardInfo> mTransBankCardList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_mybalance;
    }

    @Override
    public void initView(View view) {
        setTitle("余额");
        setPresenter(null);
        mmybalancepresenter.getUserInfo();
        mmybalancepresenter.getBalance();
        mmybalancepresenter.getTransBankCardList();
    }

    @OnClick({R.id.rl_recharge, R.id.rl_withdraw})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_recharge:

                jumpToCharge();
                break;
            case R.id.rl_withdraw:
                if (mUserAuthInfo == null) {
                    ToastUtil.showToast(this, "未获取到用户信息");
                    return;
                }
                if (mUserAuthInfo.getNumBC() <= 0) {
                    ToastUtil.showToast(this, "未绑定银行卡,请先绑定银行卡");
                    return;
                }

                if (mTransBankCardList == null) {
                    ToastUtil.showToast(this, "请绑定储蓄卡");
                    return;
                }
                Intent withdraw = new Intent(this, WithdrawActivity.class);
                withdraw.putExtra("Balance", mBalance);
                startActivity(withdraw);

                break;
        }
    }

    @Override
    public void showUserInfo(UserAuthInfo info) {
        mUserAuthInfo = info;

    }

    @Override
    public void showBalance(String balance) {
        mBalance = balance;

        if (TextUtils.isEmpty(balance)) {
            tvmaney.setText("0.00");
        } else {
            tvmaney.setText(balance);
        }
    }

    @Override
    public void setTransBankCardList(TransBankCardList<BankCardInfo> list) {
        KLog.d("setTransBankCardList" + list.getBankCardList().get(0).getCardType());

        mTransBankCardList = list;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void setPresenter(Object presenter) {
        mmybalancepresenter = new MyBalancePresenter(this);
    }

    @Override
    public void showToast(String msg) {

    }

    /**
     * 跳转到充值页面
     */
    private void jumpToCharge() {

        if (mUserAuthInfo == null) {
            ToastUtil.showToast(this, "未获取到用户信息");
            return;
        }
        if (mUserAuthInfo.getNumBC() <= 0) {
            ToastUtil.showToast(this, "未绑定银行卡,请先绑定银行卡");
            return;
        }

        Intent recharge = new Intent(this, RechargeActivity.class);
        recharge.putExtra("balance", mBalance);
        startActivity(recharge);
    }

}
